#!/bin/bash


org_hosts=/etc/hosts
if [ "$OS" == "Windows_NT" ];then
    org_hosts=/c/Windows/System32/drivers/etc/hosts
fi

bak_hosts=$org_hosts"-"`date +"%Y-%m-%d"`


tmp_hosts=/tmp/hosts
tmp_html=/tmp/html
tmp_ctx=/tmp/ctx


url=http://www.360kb.com/kb/2_150.html

curl $url -o $tmp_html > /dev/null 2>&1

if [ $? -ne 0 -o ! -f $org_hosts -o ! -f $tmp_html ];then
	exit 1
fi


sed -n '/#google hosts 2016/,/#google hosts 2016 end/p' $tmp_html  > $tmp_ctx

sed -i s'/.*#/#/' $tmp_ctx


cp -f $org_hosts $bak_hosts
cp -f $org_hosts $tmp_hosts


sed -i '/#google hosts 2016/,/#google hosts 2016 end/d' $tmp_hosts

cat $tmp_ctx >> $tmp_hosts

cp -f $tmp_hosts $org_hosts

rm -f $tmp_hosts $tmp_html $tmp_ctx

echo $org_hosts "update succ"





